<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        body {
            width: 3000px;
            height: 3000px;
        }

        .box {
            position: relative;
            width: 200px;
            height: 200px;
            margin: 600px 100px;
            background-color: pink;
        }
    </style>
</head>

<body>
    <div class="box"></div>

    <script>
        /*
            window.scroll(x,y) 让window滚到到相应坐标
            window.scrollTo(x,y) 效果同上，不兼容IE
            window.scrollBy(x,y)  相对于当前坐标移动多少距离

            element.scrollIntoView(boolean)  让元素贴顶或贴底（相对于可视区域），默认贴顶(true)  贴底(false)
        */
        window.scroll(200,200);
        console.log('window.pageYOffset', window.pageYOffset);
        window.scrollTo(400,400)
        console.log('window.pageYOffset', window.pageYOffset);
        window.scrollBy(-200,-200)
        console.log('window.pageYOffset', window.pageYOffset);

        var box =document.querySelector('.box');
        box.onclick = function () {
            box.scrollIntoView(false)
        }
    </script>
</body>

</html>